package leetcode.sort.util;

import java.util.Random;

public class SortUtil {
    private static final Random random = new Random();

    // 随机生成指定大小的数组 指定范围的数组
    public static int[] randomArray(int number, int range) {
        if (number <= 0) {
            throw new IllegalArgumentException("参数必须大于0");
        }
        int[] array = new int[number];
        for (int i = 0; i < number; i++) {
            array[i] = random.nextInt(range);
        }
        return array;
    }

    // 随机生成指定大小的数组 范围在【0-100】内的数组
    public static int[] randomArray(int number) {
        if (number <= 0) {
            throw new IllegalArgumentException("参数必须大于0");
        }
        int[] array = new int[number];
        for (int i = 0; i < number; i++) {
            array[i] = random.nextInt(100);
        }
        return array;
    }

    // 随机生成完全逆序的数组
    public static int[] reverseArray(int number, int max) {
        if (number <= 0) {
            throw new IllegalArgumentException("参数必须大于0");
        }
        int[] array = new int[number];
        for (int i = 0; i < number; i++) {
            array[i] = max--;
        }
        return array;
    }

    // 随机生成完全逆序的数组
    public static int[] reverseArray(int number) {
        if (number <= 0) {
            throw new IllegalArgumentException("参数必须大于0");
        }
        int max = number;
        int[] array = new int[number];
        for (int i = 0; i < number; i++) {
            array[i] = max--;
        }
        return array;
    }

    // 检查数组是否排序正确
    public static void check(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            if (array[i] > array[i + 1]) {
                throw new RuntimeException("排序失败");
            }
        }
    }
}
